package cn.zwk.domain.system.support;

import cn.zwk.domain.system.model.ViewComponent;
import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
@ConfigurationProperties(prefix = "menu-properties")
@Data
public class MenuProperties {

    private List<ViewComponent> components;
    private Map<String,ViewComponent> indexMap;

    @PostConstruct
    public void init(){
        indexMap = components.stream().collect(Collectors.toMap(ViewComponent::getId, Function.identity()));
    }

    public ViewComponent getComponent(String id){
        return indexMap.get(id);
    }
}
